﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using ERF;

namespace ERF.Input
{
    public class GamePadDevice : AnalogDevice
    {
        public enum DeviceSource
        {
            LeftTrigger,
            RightTrigger,
            LeftStick,
            RightStick
        };
        private DeviceSource source;
        private bool invertY = false;
        
        private const float SENSITIVITY = 35f;

        public GamePadDevice(InputHandler input, DeviceSource source, bool invertY) : base(input)
        {
            this.source = source;
            this.invertY = invertY;
        }

        public override Vector2 Location
        {
            get
            {
                Vector2 location = Vector2.Zero;

                switch (source)
                {
                    case DeviceSource.LeftStick:
                        location = handler.GamepadState.ThumbSticks.Left;
                        break;
                    case DeviceSource.RightStick:
                        location = handler.GamepadState.ThumbSticks.Right;
                        break;
                    case DeviceSource.LeftTrigger:
                        location.Y = handler.GamepadState.Triggers.Left;
                        break;
                    case DeviceSource.RightTrigger:
                        location.Y = handler.GamepadState.Triggers.Right;
                        break;
                }

                if(invertY)
                    location.Y *=-1;

                return location / SENSITIVITY;
            }
        }
    }
}
